﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="辅料采购计划录入.aspx.cs" Inherits="syc.Sale.辅料采购计划录入" %>
<head  runat="server">
    <title></title>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
    <form id="form1" runat="server" >  
     <div id="wintop" class="wintop">辅料采购计录入</div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>  
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"  UpdateMode="Conditional">
    <ContentTemplate>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
 InsertCommand="insert into 辅料采购计划0(MID,年度,月份,填报单位,填报日期,辅料ID,填报数量,计划购进量,单价,金额,用途,备注)
 values(@ID,@年度,@月份,@填报单位,@填报日期,@辅料ID,@填报数量,@填报数量,@单价,@金额,@用途,@备注);if @ID=0 begin set @ID=@@IDENTITY; end"
 DeleteCommand="delete from 辅料采购计划0 where ID=@ID or MID=@ID;"
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
 onselected="SqlDataSource1_Selected" oninserted="SqlDataSource1_Inserted">
<SelectParameters>
<asp:Parameter Name="ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="年度" DbType="Int16" Size="2" Direction="Output"/>
<asp:Parameter Name="月份" DbType="Byte"  Size="1" Direction="Output"/>
<asp:Parameter Name="填报单位" DbType="AnsiString" Size="6" Direction="Output"/>
<asp:Parameter Name="填报日期" DbType="Date"  Size="3" Direction="Output"/>
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="ID" Size="4" DbType="Int32" Direction="InputOutput"/>
<asp:Parameter Name="年度" DbType="Int16" Size="2"/>
<asp:Parameter Name="月份" DbType="Byte"  Size="1"/>
<asp:Parameter Name="辅料ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="填报单位" DbType="AnsiString" Size="6"/>
<asp:Parameter Name="填报日期" DbType="Date"  Size="3"/>
<asp:Parameter Name="填报数量" Size="4" DbType="Double"/>
<asp:Parameter Name="单价" DbType="Decimal" Size="9"/>
<asp:Parameter Name="金额" DbType="Decimal" Size="9"/>
<asp:Parameter Name="用途" DbType="String"  Size="40"/>
<asp:Parameter Name="备注" DbType="String"  Size="40"/>
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Size="4" DbType="Int32"/>
</DeleteParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
    SelectCommand="SELECT rtrim(编码) as 编码, rtrim(编码)+':' + 名称 as 名称 FROM 设备编码 where 资产=0 and 编码='3501' or 编码='3518' or 编码='3519' or 编码='3531' or 编码='3541' and len(编码)>2 order by 编码"></asp:SqlDataSource>


<asp:HiddenField ID="Cell_ID" runat="server" Value="" />
<asp:HiddenField ID="Cell_PM" runat="server" Value="" />
<asp:HiddenField ID="Cell_XH" runat="server" Value="" />
<asp:HiddenField ID="Cell_DW" runat="server" Value="" />
<asp:HiddenField ID="Cell_SL" runat="server" Value="" />
<asp:HiddenField ID="Cell_DJ" runat="server" Value="" />
<asp:HiddenField ID="Cell_YT" runat="server" Value="" />
<asp:HiddenField ID="Cell_BZ" runat="server" Value="" />
<asp:Label ID="BillID" runat="server" Text="0" Visible="False"></asp:Label>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
            SelectCommand="select '清空选择'as 品名,'0' as ID union (SELECT [品名],(cast([ID] as varchar)+'*'+cast(cast([单价] as float) as varchar)+'*'+[单位]+'*'+isnull([规格],'')) as ID  FROM [物料品种] where [物料品种].大宗=1) order by ID"></asp:SqlDataSource> 
   
     
    <asp:Panel ID="Panel1" runat="server" CssClass="panel">  
    <input type="text" style="display:none;" /> 
    <asp:Button ID="Button_Save" runat="server" CssClass="button" 
    onclick="Button_Save_Click" Text="保 存"   OnClientClick="checkInput()" />
    &nbsp;<input type="button" value="计算金额" class="button" onclick="calc();" />
    
    <!--<input type="button" value="追加一行" class="button" onclick="addrow('');" /> -->
    
    <input type="button" value="导出Excel" class="button" onclick="Export();" />

    <input type="button" value="关 闭" class="button" onclick="parent.swin_close();" /></asp:Panel>
  
 <asp:Panel ID="Panel2" runat="server" CssClass="panel">
计划年度：<asp:DropDownList ID="NianDu" runat="server" Width="80">
    <asp:ListItem Value="2008">2008</asp:ListItem>
    <asp:ListItem Value="2009">2009</asp:ListItem>
    <asp:ListItem Value="2010">2010</asp:ListItem>
    <asp:ListItem Value="2011">2011</asp:ListItem>
    <asp:ListItem Value="2012">2012</asp:ListItem>
    <asp:ListItem Value="2013">2013</asp:ListItem>
    <asp:ListItem Value="2014">2014</asp:ListItem>
    <asp:ListItem Value="2015">2015</asp:ListItem>
    <asp:ListItem Value="2016">2016</asp:ListItem>
    <asp:ListItem Value="2017">2017</asp:ListItem>
    <asp:ListItem Value="2018">2018</asp:ListItem>
    <asp:ListItem Value="2019">2019</asp:ListItem>
    <asp:ListItem Value="2020">2020</asp:ListItem>
    </asp:DropDownList>
月份：<asp:DropDownList ID="YueFen" runat="server" Width="80">
    <asp:ListItem Value="1">1</asp:ListItem>
    <asp:ListItem Value="2">2</asp:ListItem>
    <asp:ListItem Value="3">3</asp:ListItem>
    <asp:ListItem Value="4">4</asp:ListItem>
    <asp:ListItem Value="5">5</asp:ListItem>
    <asp:ListItem Value="6">6</asp:ListItem>
    <asp:ListItem Value="7">7</asp:ListItem>
    <asp:ListItem Value="8">8</asp:ListItem>
    <asp:ListItem Value="9">9</asp:ListItem>
    <asp:ListItem Value="10">10</asp:ListItem>
    <asp:ListItem Value="11">11</asp:ListItem>
    <asp:ListItem Value="12">12</asp:ListItem>
    </asp:DropDownList>
  填报单位：<asp:DropDownList ID="TianBao" runat="server" DataSourceID="SqlDataSource2" Width="160" 
        DataTextField="名称" DataValueField="编码">
    </asp:DropDownList>
    填报日期：<asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="110px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
<span style="margin-left:20px;"></span>
</asp:Panel>
 <asp:Panel ID="Msg" runat="server" CssClass="panel2">
        <asp:Label ID="Message" runat="server" Text="·准备就绪" CssClass="prompt"></asp:Label>      
 </asp:Panel>
</ContentTemplate>
   </asp:UpdatePanel>   
<div style="text-align:center;">
<script>    putBillHead();</script>
<asp:Panel ID="Panel5" runat="server">

<style>
tr{height:16pt;}
td.nm{border:.5pt solid #000000;font-size:11pt;text-align:center;}
td.nb{border:none;font-size:11pt;text-align:center;}
div{word-break:break-all;}
</style>
<table id=mt border=0 cellpadding=0 style=border-collapse:collapse>
<tr style=height:24pt>
<td class=nb colspan=9 style=font-size:18pt;>辅 料 采 购 计 划 表</td>
</tr>
<tr>
<td class=nb colspan=4 style=text-align:left;>&nbsp;填报单位：<%=this.TianBao.SelectedItem.Text.Split(new char[]{':'})[1] %></td>
<td class=nb colspan=2><%=this.Date1.Text%></td>
<td class=nb colspan=3 style=text-align:right;>编号：SYC/ZJ-SC-01&nbsp;</td>
</tr>
</tr>
<tr style=height:20pt>
<td class=nm style=width:30pt;>序号</td>
<td class=nm style=width:90pt;>品 名</td>
<td class=nm style=width:90pt;>型 号</td>
<td class=nm style=width:50pt;>单 位</td>
<td class=nm style=width:50pt;>数 量</td>
<td class=nm style=width:60pt;>单价(元)</td>
<td class=nm style=width:80pt;>金额(元)</td>
<td class=nm style=width:90pt;>用 途</td>
<td class=nm style=width:90pt;>备 注</td>
</tr>
<%     
    for(int i=0;i<15;i++) {%>
<tr>
<td class=nm><%=i+1 %></td>
<td class=nm tabindex="0" onfocus="dodisplay(this);"></td>
<td class=nm></td>
<td class=nm></td>
<td class=nm><div tabindex=0 contentEditable style=width:50pt; ></div></td>
<td class=nm><div tabindex=0 contentEditable style=width:60pt; ></div></td>
<td class=nm></td>
<td class=nm><div tabindex=0 contentEditable style=width:90pt;></div></td>
<td class=nm><div tabindex=0 contentEditable style=width:90pt;></div></td>
</tr>
<%} %>
<tr>
<td class=nm></td>
<td class=nm></td>
<td class=nm></td>
<td class=nm></td>
<td class=nm></td>
<td class=nm style=text-align:right;>合计：</td>
<td class=nm></td>
<td class=nm></td>
<td class=nm></td>
</tr>

    </asp:Panel>
</table>

<script>    putBillFoot();</script>
</div>
 
   <asp:DropDownList runat="server" ID="pmlist" DataSourceID="SqlDataSource3" 
            DataTextField="品名" DataValueField="ID" Width="90pt"></asp:DropDownList>
 
 </form>
 <form id="form2" method="post" action="/PageExport.ashx">
<input type="hidden" name="filename" value="辅料采购计划.xls" />
<input type="hidden" name="content" value="" />
</form>
<script>
    var TianBao = document.getElementById("TianBao");

    TianBao.onchange = function() {
        mt.rows[1].cells[0].innerHTML = "&nbsp;填报单位：" + TianBao.options[TianBao.selectedIndex].text.split(":", 2)[1];
    };
    var Date1 = document.getElementById("Date1");
    Date1.onchange = function() {
        mt.rows[1].cells[1].innerHTML = Date1.value;
    };
    var IDList = new Array();
    var ghlist = document.getElementById("pmlist");
    var tar;  
    ghlist.style.display = "none";
    ghlist.style.position = "absolute";

  
    ghlist.onchange = function() {
        tar.innerHTML = ghlist.options[ghlist.selectedIndex].text;
        var txt = ghlist.options[ghlist.selectedIndex].value.split("*", 4);
        if (txt == 0) {
            IDList[tar.parentElement.rowIndex - 3] = "";
            tar.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
        } else {
            tar.nextSibling.innerHTML = txt[3];
            tar.nextSibling.nextSibling.innerHTML = txt[2];
            //tar.nextSibling.nextSibling.firstChild.innerHTML ="";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = txt[1];
           // document.getElementById("HiddenField1").value = ghlist.options[ghlist.selectedIndex].text;
        }
    };
    ghlist.onblur = function() {
        ghlist.style.display = "none";

        tar.innerHTML = ghlist.options[ghlist.selectedIndex].text;
        var txt = ghlist.options[ghlist.selectedIndex].value.split("*", 4);
        if (txt == 0) {
            tar.innerHTML = "";
            IDList[tar.parentElement.rowIndex - 3] = "";
            tar.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";


        } else {
            IDList[tar.parentElement.rowIndex - 3] = txt[0];
            tar.nextSibling.innerHTML = txt[3];
            tar.nextSibling.nextSibling.innerHTML = txt[2];
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = txt[1];
         //   document.getElementById("HiddenField1").value = ghlist.options[ghlist.selectedIndex].text;
                  
        }
    };

    function dodisplay(o) {       
        tar = o;         
        ghlist.style.left = (getObjectLeft(o) -2) + "px";
        ghlist.style.top = (getObjectTop(o)-1)+ "px";
        ghlist.style.display = "block";
        ghlist.selectedIndex = 0;
        ghlist.focus();
      
     
    }
    //计算金额
    function calc() {
        var mt = document.getElementById("mt");
        var rows = 0;       
        var n, p;
        var total = 0;
        for (var i = 3; i < mt.rows.length - 1; i++) {
            row = mt.rows[i];
            n = Number(row.cells[4].innerText || row.cells[4].textContent);
            if (n == NaN) {
                n = -1;
            }

            p = Number(row.cells[5].innerText || row.cells[5].textContent);
            if (p == NaN) {
                p = -1;
            }
            if (n > 0 && p > 0) {
                row.cells[6].innerHTML = n * (p * 1000) / 1000;
                total += n * p;
            }
            else {
                row.cells[6].innerHTML = "";
            }
        }
        mt.rows[mt.rows.length - 1].cells[6].innerHTML = total;
    }
    //输入检测
    function checkInput() {    
        calc();
        var txt;
        var Cell_ID = document.getElementById("Cell_ID");
        var Cell_PM = document.getElementById("Cell_PM");
        var Cell_XH = document.getElementById("Cell_XH");
        var Cell_DW = document.getElementById("Cell_DW");
        var Cell_SL = document.getElementById("Cell_SL");
        var Cell_DJ = document.getElementById("Cell_DJ");
        var Cell_YT = document.getElementById("Cell_YT");
        var Cell_BZ = document.getElementById("Cell_BZ");

        Cell_ID.value = "";
        Cell_PM.value = "";
        Cell_XH.value = "";
        Cell_DW.value = "";
        Cell_SL.value = "";
        Cell_DJ.value = "";
        Cell_YT.value = "";
        Cell_BZ.value = "";
        var n, p;
        for (var i = 3; i < mt.rows.length - 1; i++) {          
            if (IDList[i - 3] > 0) {
                Cell_ID.value += "|" + IDList[i - 3];
                
                
                txt = mt.rows[i].cells[1].innerText;
                if (txt == null) txt = mt.rows[i].cells[1].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_PM.value += "|=*" + txt;

                txt = mt.rows[i].cells[2].innerText;
                if (txt == null) txt = mt.rows[i].cells[2].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_XH.value += "|=*" + txt;
               

                txt = mt.rows[i].cells[3].innerText;
                if (txt == null) txt = mt.rows[i].cells[3].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_DW.value += "|=*" + txt;


                txt = mt.rows[i].cells[4].innerText;
                if (txt == null) txt = mt.rows[i].cells[4].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                if (txt == "") continue;
                Cell_SL.value += "|" + txt;

                txt = mt.rows[i].cells[5].innerText;
                if (txt == null) txt = mt.rows[i].cells[5].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_DJ.value += "|" + txt;

                txt = mt.rows[i].cells[7].innerText;
                if (txt == null) txt = mt.rows[i].cells[7].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_YT.value += "|=*" + txt;

                txt = mt.rows[i].cells[8].innerText;
                if (txt == null) txt = mt.rows[i].cells[8].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_BZ.value += "|=*" + txt;
            }          
        }
    }

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.tagName != "DIV") return;
        if (event.keyCode == 13) {
            calc();
            e.keyCode = 9 
        }     
    }

    
    
    
    
    //导出Excel
    function Export() {
        form2.content.value =
"<html xmlns:o='urn:schemas-microsoft-com:office:office'\nxmlns:x='urn:schemas-microsoft-com:office:excel'\nxmlns='http://www.w3.org/TR/REC-html40'>\n<head>\n<meta http-equiv=Content-Type content='text/html; charset=utf-8'>\n<style>\n<!--table\n@page\n{mso-header-data:;\nmso-footer-data:;\nmargin:.79in .31in .79in .31in;\nmso-header-margin:.51in;\nmso-footer-margin:.51in;\nmso-page-orientation:landscape;\nmso-horizontal-page-align:center;\n}\n-->\n</style>\n<!--[if gte mso 9]><xml>\n<x:ExcelWorkbook>\n<x:ExcelWorksheets>\n<x:ExcelWorksheet>\n<x:Name>辅料采购计划</x:Name>\n<x:WorksheetOptions>\n<x:DefaultRowHeight>285</x:DefaultRowHeight>\n<x:Print>\n<x:ValidPrinterInfo/>\n<x:Scale>100</x:Scale>\n<x:PaperSizeIndex>9</x:PaperSizeIndex>\n<x:HorizontalResolution>200</x:HorizontalResolution>\n<x:VerticalResolution>200</x:VerticalResolution>\n</x:Print>\n<x:Selected/>\n<x:Panes>\n<x:Pane>\n<x:Number>3</x:Number>\n<x:ActiveRow>0</x:ActiveRow>\n<x:ActiveCol>0</x:ActiveCol>\n</x:Pane>\n</x:Panes>\n</x:WorksheetOptions>\n</x:ExcelWorksheet>\n</x:ExcelWorkbook>\n</xml><![endif]-->\n</head>\n<body>"
            + document.getElementById("Panel5").innerHTML.replace(/<div [^>]*>/gi, "").replace(/<\/div>/gi, "");
+"</body></html>";
        form2.submit();
    }
</script>
</body>
</html>

